#include <stdio.h>
#include <set>
#include <mutex>
#include "thread/event_loop_thread.h"
#include "thread/event_loop_thread_pool.h"
#include "net/tcp_client.h"

static rr::nio::EventLoopThread::Sptr loop_thread;

static rr::nio::TcpClient::Sptr tcp_client;

static void CloseCallback(rr::nio::TcpConnectionVar conn)
{
    printf("TcpClinet CloseCallback: conn[%p]\n", conn.get());

}

static void ConnectionCallback(rr::nio::TcpConnectionVar conn)
{
    printf("TcpClinet ConnectionCallback: conn[%p]\n", conn.get());
}

void TestTcpClinetStart()
{
    if(!loop_thread) {
        loop_thread = std::make_shared<rr::nio::EventLoopThread>();
        loop_thread->StartLoop();
    }

    tcp_client = std::make_shared<rr::nio::TcpClient>(loop_thread->GetLoop());

    tcp_client->SetConnectionCallback(ConnectionCallback);
    tcp_client->SetCloseCallback(CloseCallback);

    tcp_client->Start();
}

void TestTcpClinetStop()
{
    tcp_client->Stop();
    tcp_client.reset();
}